<?php
/**
 * Zend_Filter_Input extension
 * 
 * @package	Nuclide-Mvc
 * @version $Id$
 */

Zend_Loader::loadClass('Zend_Filter_Input');

/**
 * Zend_Filter_Input extension
 * 
 * @package	Nuclide-Mvc
 */
class nuc_Filter_Input extends Zend_Filter_Input
{
	/**
	 * Original input data
	 *
	 * @var array
	 */
	private $_originalData = array();
	
	/**
	 * Public constructor
	 *
	 * @param	array 	Filter rules
	 * @param	array 	Validator rules
	 * @param	array 	OPTIONAL input data
	 * @param	array 	OPTIONAL filter options
	 */
	public function __construct( array $filterRules, array $validatorRules, $data = null, $options = null ) {
		parent::__construct( $filterRules, $validatorRules, $data, $options );
		
		$this->_originalData = $this->_data;
	}
	
	/**
	 * Sets input data
	 *
	 * @param	array 	New data
	 */
	public function setData( array $data ) {
		parent::setData( $data );
		
		$this->_originalData = $this->_data;
	}	
	
	/**
	 * Fetches original input data
	 *
	 * @param	string		OPTIONAL Parameter name
	 * @param 	array		OPTIONAL Parameter source
	 * @return	Input data
	 */
	public function getData( $param = false, $source = false ) {
		$ret = array();
		if( !$source ) {
			$source = $this->_originalData;
		}
		
		if( $param ) {
			$ret = htmlentities( $source[ $param ], ENT_COMPAT, 'UTF-8' );
		} else {
			foreach( $source as $key => $value ) {
				if( is_array( $value ) ) {
					$ret[ $key ] = $this->getData( false, $value );
				} else {
					$ret[ $key ] = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
				}
			}
		}

		return $ret;
	}
}
?>